home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / amisl090.zip / RBKEYSWP.ASM < prev    next >
Assembly Source File  |  1992-09-12  |  6KB  |  201 lines

  1. ;**************************************************************************
  2. ;*                                      *
  3. ;*   RBkeyswap     v3.0       9/12/92                      *
  4. ;*   (c) Copyright 1989, 1991, 1992 Ralf Brown                  *
  5. ;*                                      *
  6. ;*   Permission is granted to redistribute unmodified copies in their      *
  7. ;*   entirety.    Modified copies may be distributed provided that they      *
  8. ;*   are clearly marked as modified and the original unmodified source      *
  9. ;*   code is distributed together with the modification.          *
  10. ;*                                      *
  11. ;*   ------------------------------------------------------------------   *
  12. ;*                                      *
  13. ;*   RBkeyswap is a program to fix the IBM's enhanced keyboard, which     *
  14. ;*   places the Escape, Control, and CapsLock keys in the wrong places.   *
  15. ;*   After running RBkeyswap, Escape and `/~ will be exchanged, as will   *
  16. ;*   the left control key and the CapsLock key.  The right control key      *
  17. ;*   will be unaffected.                          *
  18. ;*                                      *
  19. ;*   RBkeyswap loads itself high (no need for LOADHI or LH) into either   *
  20. ;*   an XMS upper memory block or a DOS 5.0 UMB.  If neither is avail-      *
  21. ;*   able, RBkeyswap will go resident in low memory, using just 224      *
  22. ;*   bytes (it needs a mere 160 bytes in high memory).  Note that it will *
  23. ;*   use 272 bytes under DOS 2.x, because those versions force all TSRs   *
  24. ;*   to leave at least that much resident.                  *
  25. ;*                                      *
  26. ;*   You need a BIOS which provides the keyboard intercept on INT 15h.      *
  27. ;*   If your BIOS does not support this, RBkeyswap will merely use up      *
  28. ;*   memory without doing anything.                      *
  29. ;*                                      *
  30. ;*   Usage:   RBKEYSWP I    install                      *
  31. ;*          RBKEYSWP R    remove from memory              *
  32. ;*                                      *
  33. ;*   ------------------------------------------------------------------   *
  34. ;*                                      *
  35. ;*   Rebuilding RBkeyswap:                          *
  36. ;*      TASM RBKEYSWP                           *
  37. ;*      TLINK /T RBKEYSWP AMIS                      *
  38. ;*                                      *
  39. ;**************************************************************************
  40.  
  41. __TINY__ equ 1                ; using Tiny model
  42.     INCLUDE AMIS.MAC
  43.  
  44.     @Startup 2,00               ; need DOS 2.00
  45.                     ; this macro also takes care of declaring
  46.                     ; all the segments in the required order
  47.  
  48. ;-----------------------------------------------------------------------
  49. ;
  50. VERSION_NUM equ 0300h    ; v3.00
  51. VERSION_STR equ "3.00"
  52.  
  53. ;-----------------------------------------------------------------------
  54. ;
  55. ; useful macros
  56. ;
  57. LODSB_ES MACRO
  58.     DB 26h,0ACh    ; LODSB ES:
  59.     ENDM
  60.  
  61. ;-----------------------------------------------------------------------
  62. ; Put the resident code into its own segment so that all the offsets are
  63. ; proper for the new location after copying it into a UMB or down into
  64. ; the PSP.
  65. ;
  66. TSRcode@
  67.  
  68. ;-----------------------------------------------------------------------
  69. ; Declare the interrupt vectors hooked by the program, then set up the
  70. ; Alternate Multiplex Interrupt Spec handler
  71. ;
  72.     HOOKED_INTS 15h
  73.     ALTMPX    'Ralf B','RBkeyswp',VERSION_NUM
  74.  
  75. ;-----------------------------------------------------------------------
  76. ; Now the meat of the resident portion, the keyboard intercept handler.
  77. ; We can save one byte by specifying the hardware reset handler set up by
  78. ; the ALTMPX macro above
  79. ;
  80. ISP_HEADER 15h,hw_reset_2Dh
  81.        cmp    ah,4Fh            ; scan code translation?
  82.        jne    not_ours        ; if not, chain immediately
  83.        cmp    al,0E1h         ; is it a special key such as "Pause"?
  84.        je    int15_setbranch
  85.        cmp    al,0E0h         ; or a right-{alt,ctrl}?
  86. branch:                 ; (if prev scan was E0h or E1h, we will
  87.                     ;   branch unconditionally)
  88.        je    int15_setbranch     ; the opcode here gets toggled between
  89.                     ;   JE and JMP SHORT as needed
  90.        shl    al,1            ; move break bit into CF
  91.        pushf                ;   and remember it for later
  92.        cmp    al,1Dh*2        ; ctrl?
  93.        je    ctrl_or_capslock
  94.        cmp    al,3Ah*2        ; capslock?
  95.        je    ctrl_or_capslock
  96.        cmp    al,01h*2        ; ESC?
  97.        je    esc_or_tilde
  98.        cmp    al,29h*2        ; backquote/tilde key?
  99.        jne    int15_no_xlat
  100. esc_or_tilde:
  101.        xor    al,0Fh*2        ; (AL xor 0F) xor 27 == (AL xor 28h)
  102.                     ; 01h -> 29h, 29h -> 01h
  103.                     ; thus esc and tilde swapped
  104. ctrl_or_capslock:
  105.        xor    al,27h*2        ; 1Dh -> 3Ah, 3Ah -> 1Dh
  106.                     ; thus left-ctrl and capslock swapped
  107. int15_no_xlat:
  108.        popf                ; retrieve break bit in CF
  109.        rcr    al,1            ;   and add to translated scan code
  110.        jmp short int15_done
  111.  
  112. int15_setbranch:
  113.        xor    byte ptr cs:branch,(74h xor 0EBh) ; toggle between JE and JMP
  114. int15_done:
  115.        stc                ; use the scan code
  116. not_ours:
  117.        jmp    ORIG_INT15h
  118.  
  119. TSRcodeEnd@
  120.  
  121. ;-----------------------------------------------------------------------
  122.  
  123. _TEXT SEGMENT 'CODE'
  124.     ASSUME cs:_TEXT,ds:NOTHING,es:NOTHING,ss:NOTHING
  125.  
  126. banner    db 'RBkeyswap v',VERSION_STR,'  (c) Copyright 1989,1991,1992 Ralf Brown',13,10
  127.     db "$"
  128. usage    db 9,'Swaps Esc/tilde and CapsLock/LeftCtrl',13,10
  129.     db 'Usage:',9,'RBKEYSWP I',9,'install in memory',13,10
  130.     db 9,'RBKEYSWP R',9,'remove from memory',13,10
  131.     db '$'
  132. installed_msg     db "Installed.",13,10,"$"
  133. already_inst_msg db "Already installed.",13,10,"$"
  134. cant_remove_msg  db "Can't remove from memory.",13,10,"$"
  135. uninstalled_msg  db "Removed.",13,10,"$"
  136.  
  137.     @Startup2    Y
  138.     push    ds
  139.     pop    es
  140.     ASSUME    ES:_INIT
  141.     push    cs
  142.     pop    ds
  143.     ASSUME    DS:_TEXT
  144.     ;
  145.     ; say hello 
  146.     ;
  147.     DISPLAY_STRING banner
  148.     mov    bx,1000h        ; set memory block to 64K
  149.     mov    ah,4Ah
  150.     int    21h
  151.     mov    si,81h            ; SI -> command line
  152.     cld                ; ensure proper direction for string ops
  153. cmdline_loop:
  154.     lodsb_es
  155.     cmp    al,' '            ; skip blanks and tabs on commandline
  156.     je    cmdline_loop
  157.     cmp    al,9
  158.     je    cmdline_loop
  159.     and    al,0DFh            ; force to uppercase
  160.         cmp     al,'I'
  161.         je      installing
  162.     cmp    al,'R'
  163.     je    removing
  164.     jmp    show_usage
  165. installing:
  166.     ;
  167.     ; place any necessary pre-initialization here
  168.     ;
  169.     INSTALL_TSR ,BEST,TOPMEM,inst_notify,already_installed
  170.  
  171. removing:
  172.     UNINSTALL cant_uninstall
  173.     push    cs
  174.     pop    ds
  175.     DISPLAY_STRING uninstalled_msg
  176.         mov     ax,4C00h
  177.     int    21h
  178.  
  179. show_usage:
  180.     mov    dx,offset _TEXT:usage
  181.     jmp short exit_with_error
  182. cant_uninstall:
  183.     mov    dx,offset _TEXT:cant_remove_msg
  184.     jmp short exit_with_error
  185. already_installed:
  186.     mov    dx,offset _TEXT:already_inst_msg
  187. exit_with_error:
  188.     mov    ah,9
  189.     int    21h
  190.     mov    ax,4C01h
  191.     int    21h
  192.  
  193. inst_notify:
  194.     DISPLAY_STRING installed_msg
  195.     ret
  196.  
  197. _TEXT ENDS
  198.  
  199.      end INIT
  200.  
  201.